<template>
  <!-- {{ props.columnData.visableNewFlag + ' ' + props.columnData.visableModifyFlag + ' ' + props.columnData.visableChangeFlag }} -->
  <!-- 需要校验 -->
  <template v-if="props.rowIndex >= 0 && props.columnData.fieldCode !== '' && props.columnData.requiredFlag">
    <el-tooltip
      placement="bottom"
      :content="props.itemData.isError[props.columnData.fieldCode].msg"
      effect="light"
      v-if="!props.itemData.isError[props.columnData.fieldCode].status"
    >
      <div
        v-if="!props.itemData.isEdit && props.columnData.fieldTypeCode !== 'NONE'"
        class="table-text"
        :class="
          !props.itemData.isError[props.columnData.fieldCode].status
            ? 'error'
            : props.rowIndex === props.currentRowIndex && props.colIndex === props.currentColumnIndex
            ? 'active'
            : ''
        "
      >
        <el-icon class="copy" v-if="props.setCopyMode"><CopyDocument /></el-icon>
        <span class="text">{{ props.itemData[props.columnData.fieldCode] || '--' }}</span>
        <el-icon class="edit"><EditPen /></el-icon>
      </div>
      <div
        class="table-text"
        :class="
          !props.itemData.isError[props.columnData.fieldCode].status
            ? 'error'
            : props.rowIndex === props.currentRowIndex && props.colIndex === props.currentColumnIndex
            ? 'active'
            : ''
        "
        v-if="props.itemData.isEdit && props.columnData.fieldTypeCode !== 'NONE'"
      >
        <component :is="compenentUrl(props.columnData)" :columnData="props.columnData" :itemData="props.itemData" :rules="props.rules"></component>
      </div>
    </el-tooltip>
    <template v-else>
      <div
        v-if="!props.itemData.isEdit && props.columnData.fieldTypeCode !== 'NONE'"
        class="table-text"
        :class="
          !props.itemData.isError[props.columnData.fieldCode].status
            ? 'error'
            : props.rowIndex === props.currentRowIndex && props.colIndex === props.currentColumnIndex
            ? 'active'
            : ''
        "
      >
        <el-icon class="copy" v-if="props.setCopyMode"><CopyDocument /></el-icon>
        <span class="text">{{ props.itemData[props.columnData.fieldCode] || '--' }}</span>
        <el-icon class="edit"><EditPen /></el-icon>
      </div>
      <div
        class="table-text"
        :class="
          !props.itemData.isError[props.columnData.fieldCode].status
            ? 'error'
            : props.rowIndex === props.currentRowIndex && props.colIndex === props.currentColumnIndex
            ? 'active'
            : ''
        "
        v-if="props.itemData.isEdit && props.columnData.fieldTypeCode !== 'NONE'"
      >
        <component :is="compenentUrl(props.columnData)" :columnData="props.columnData" :itemData="props.itemData" :rules="props.rules"></component>
      </div>
    </template>
  </template>
  <!-- 不需要校验 -->
  <template v-if="props.rowIndex >= 0 && props.columnData.fieldCode !== '' && !props.columnData.requiredFlag">
    <div
      v-if="!props.itemData.isEdit && props.columnData.fieldTypeCode !== 'NONE'"
      class="table-text"
      :class="props.rowIndex === props.currentRowIndex && props.colIndex === props.currentColumnIndex ? 'active' : ''"
    >
      <el-icon class="copy" v-if="props.setCopyMode"><CopyDocument /></el-icon>
      <span class="text">{{ props.itemData[props.columnData.fieldCode] || '--' }}</span>
      <el-icon class="edit"><EditPen /></el-icon>
    </div>
    <div class="table-text" v-if="props.itemData.isEdit && props.columnData.fieldTypeCode !== 'NONE'">
      <!-- <base-form :columnData="item" :itemData="row"></base-form> -->
      <component :is="compenentUrl(props.columnData)" :columnData="props.columnData" :itemData="props.itemData" :rules="props.rules"></component>
      <!-- {{ compenentUrl(item) }} -->
    </div>
  </template>
</template>

<script setup>
import { watch } from 'vue-demi'
import baseForm from './baseForm.vue'
import { setComponents } from './hooks/tableFormItem'
// 设置form 类型
const { compenentUrl } = setComponents({})
const props = defineProps({
  columnData: {
    type: Object,
    default: () => {}
  },
  itemData: {
    type: Object,
    default: () => {}
  },
  colIndex: {
    type: Number,
    default: 0
  },
  rowIndex: {
    type: Number,
    default: 0
  },
  currentRowIndex: {
    type: Number,
    default: 0
  },
  currentColumnIndex: {
    type: Number,
    default: 0
  },
  setCopyMode: {
    type: Boolean,
    default: false
  },
  rules: {
    type: Object,
    default: () => {}
  }
}) 
</script>

<style lang="scss" scoped>
.table-text {
  width: 100%;
  user-select: none;
  border: 1px solid transparent;
  border-radius: var(--el-input-border-radius, var(--el-border-radius-base));
  transition: all 0.3s; // position: relative;
  display: flex;
  align-items: center;
  padding: 1px;
  min-height: 34px;
  .text {
    padding-left: 10px;
    flex: 1;
    line-height: 30px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .el-icon {
    opacity: 0;
    color: var(--el-color-info-light-3);
    &.copy {
      display: none;
      opacity: 0;
    }
  }
  &.error {
    // border-color: var(--el-color-danger);
    box-shadow: 0 0 0 1px var(--el-color-danger) inset;
  }
  &.active {
    // border-color: var(--el-color-danger);
    // box-shadow: 0 0 0 1px var(--el-color-primary) inset;
    .copy {
      display: block;
      opacity: 1;
    }
  }
}
</style>
